package p366;/**
 * @Author：ming
 * @Date：2023/10/14 10:13 AM
 * @Filename：Lc2895
 */

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author ming
 */
public class Lc2895 {
    public int minProcessingTime(List<Integer> processorTime, List<Integer> tasks) {
        Collections.sort(processorTime);
        Collections.sort(tasks, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        int min = 0;
        int time = 0;

        for (int i = 0; i < processorTime.size(); i++) {
            int index = 4*i;
            int a = tasks.get(index);
            int b = tasks.get(index+1);
            int c = tasks.get(index+2);
            int d = tasks.get(index+3);
            time =processorTime.get(i)+ Math.max(Math.max(a, b), Math.max(c, d));
            if(min<time){
                min = time;
            }
        }

        return min;
    }
}
